// pages/fenlei2/fenlei2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    index: 15,
    yida: 0,              // 控制已答题数
    before: "",           // 答题规则
    begin: "true",       // 控制答题面显示
    end: "true",         // 控制结果面显示
    answer: "",           // 答对恭喜，打错提示答案
    bcDaan: "",           // 控制提示的样式
    bc_wrong: "#be1057",
    value: "",
  },
  // 答题规则，开始答题
  begin: function () {
    this.setData({
      before: "true",
      begin: "",
    })
  },
  
  // 下一题
  xia: function () {
    if (this.data.index < 24) {
      this.setData({
        index: this.data.index + 1,
        answer: ""
      })
    } else {
      this.setData({
        begin: "true",
        end: "",
      })
    }
  },
  // 提交按钮
  form: function (e) {
    var value = e.detail.value.psw;
    var answer = this.data.list[this.data.index].answer
    if (value == answer) {
      this.setData({
        placeholder: "请输入答案",
        value: "",
        yida: this.data.index - 4
      })
      this.xia();
    } else {
      this.setData({
        answer: "答案错误，再接再厉",
        bcDaan: this.data.bc_wrong
      })
    }
  },
  shoucang: function (e) {
    var pid = e.currentTarget.id;
    var timu = this.data.list[this.data.index].timu;
    var answer = this.data.list[this.data.index].answer;
    var fenlei = this.data.list[this.data.index].fenlei;
    var url = "http://127.0.0.1:3000/user/toshoucang?pid=" + pid + "&timu=" + timu + "&answer=" + answer + "&fenlei=" + fenlei;
    console.log(url)
    wx.request({
      url: url,
      method: "GET",
      success: (res) => {

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.fenlei2();
  },
  fenlei2: function () {
    var url = "http://127.0.0.1:3000/index/tiaozhan";
    wx.request({
      url: url,
      method: "GET",
      success: (res) => {
        this.setData({
          list: res.data.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})